Page({
  data: {
    price: 0,
    carId: 0,
    colorIndex: 0,
    imageIndex: 0,
    colors: [
      'https://img.v.mifile.cn/nr-upload-car/image_b2d93c50eedf48d2beabe9641d9d76d0_1710423303526.jpg',
      'https://img.v.mifile.cn/nr-upload-car/image_788d296a61614fd290b61998196f6665_1711653564867.jpg',
      'https://img.v.mifile.cn/nr-upload-car/image_e5d6643f837544d6aa1708fd12a72e2c_1710423306424.jpg',
    ],
    carColorImages: [
      [
        'https://img.v.mifile.cn/nr-upload-car/image_4cbcc770a0064e89992a9eb4a2e7ac19_1711194659195.jpg',
        'https://img.v.mifile.cn/nr-upload-car/image_b5a0764d121748f3bc1a47e94da82538_1711194661092.jpg',
        'https://img.v.mifile.cn/nr-upload-car/image_1d9c0217d6db4ed3b558611ba9c6cf19_1711194658937.jpg',
      ],
      [
        'https://img.v.mifile.cn/nr-upload-car/image_948c0dc643dd48d48aa711707155d220_1711189162526.jpg',
        'https://img.v.mifile.cn/nr-upload-car/image_e3e3b99614af46b98f4e496ee78dab4a_1711194661271.jpg',
        'https://img.v.mifile.cn/nr-upload-car/image_064644b4f30f4661968863099fcb5e97_1711194659680.jpg',
      ],
      [
        'https://img.v.mifile.cn/nr-upload-car/image_e87d02a5af3d41679cc816e7b23d6475_1711194658595.jpg',
        'https://img.v.mifile.cn/nr-upload-car/image_a338e3cfb91b4cf1b9ecfecbad9f225f_1711194660906.jpg',
        'https://img.v.mifile.cn/nr-upload-car/image_416b83965027449481d416372a86b5a6_1711194658441.jpg',
      ],
    ],
  },

  onLoad(options) {
    this.setData({ price: options.price, carId: options.carId });
  },

  carImageHandleTap(event) {
    const index = event.currentTarget.dataset.index;
    this.setData({
      imageIndex: index,
    });
  },

  colorHandleTap(event) {
    const index = event.currentTarget.dataset.index;
    this.setData({
      colorIndex: index,
    });
  },

  goToConfirmPage(e) {
    const imageUrl = this.data.carColorImages[this.data.colorIndex][
      this.data.imageIndex
    ];
    const carId = this.data.carId;
    wx.navigateTo({
      url: `/pages/confirm/confirm?carId=${carId}&imageUrl=${imageUrl}`,
    });
  },
});
